#!/bin/ash -efu
#
# mki-image-prepare
#
# This file is part of mkimage
# Copyright (C) 2007-2009  Alexey Gladkov <gladkov.alexey@gmail.com>
#
# This file is covered by the GNU General Public License,
# which should be included with mkimage as the file COPYING.
#

. "${0%/*}"/mki-sh-functions
. "${0%/*}"/mki-sh-image-prepare

verbose "has started executing."

[ -d "$subchroot" ] ||
	hsh_initroot "$subdir"

ln $verbose -nsf -- "$WORKDIRNAME/chroot" "$chroot/.image"

[ -f "$chroot/.fakedata" ] && [ -f "$chroot/.image/.fakedata" ] ||
	exit 0

inode1="$(stat -c '%i' "$chroot/.fakedata")"
inode2="$(stat -c '%i' "$chroot/.image/.fakedata")"
[ "$inode1" != "$inode2" ] ||
	exit 0

# NB: /.fakedata will get overwritten by the time hsh-run exits
mki-run sh -c 'rm -f /.fakedata. &&
	cat /.fakedata /.image/.fakedata > /.fakedata. &&
	ln -f /.fakedata. /.image/.fakedata'
mv -f -- "$chroot/.fakedata." "$chroot/.fakedata"
